package com.project.housesalesystem.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.housesalesystem.bean.House;
import com.project.housesalesystem.common.PageResult;
import com.project.housesalesystem.common.Results;
import com.project.housesalesystem.service.HouseService;
<<<<<<< HEAD
import jakarta.servlet.http.HttpServletRequest;
=======
>>>>>>> 66dcee4e153c16ef05fd0c7e1ed9f414a0bf0bc9
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

<<<<<<< HEAD
=======
import javax.servlet.http.HttpServletRequest;
>>>>>>> 66dcee4e153c16ef05fd0c7e1ed9f414a0bf0bc9
import java.util.Map;

@RequestMapping("user")
@RestController
public class UsersHouseController {
    private static final Logger logger = LoggerFactory.getLogger(AdminHouseController.class);

    @Autowired
    private HouseService houseService;


    /**
     * 前端列表
     */

    @RequestMapping("/list")
    public PageResult list(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(), JSONObject.toJSONString(params));

        IPage<House> page = houseService.getHousePage(params);

        return PageResult.success(page);
    }

    /**
     * 前端详情
     */
    @RequestMapping("/detail/{id}")
    public Results detail(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        House house = houseService.getById(id);
        if(house !=null){

            return Results.ok().put("data", house);
        }else {
            return Results.error(511,"查不到数据");
        }
    }


}


